import pathlib
import time
import re
import typing
import os
import yaml
import ctypes
import psutil
import subprocess
import requests
import winsound
import datetime
from selenium.webdriver.edge.webdriver import WebDriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import *
from rich import print


def _Custom_Safe_Click(element: WebElement, Delay: float = 0.5):
    """安全点击,防止一些元素无法进行点击.

    Args:
        element (WebElement): 执行点击的 Element 元素对象.
        Delay (float, optional): _description_. Defaults to 0.5.
    """

    # 1.判断元素是否存在
    if not element:
        raise Exception("元素对象为空!无法进行点击操作!")
        print(e)

    # 执行点击
    try:
        element.parent.execute_script(
            "arguments[0].scrollIntoView({block: 'center', inline: 'center'});",
            element)
        element.click()
    except (ElementClickInterceptedException, ElementNotInteractableException):
        element.parent.execute_script(
            "arguments[0].click();", element
        )
